<script type="text/javascript" src="../media/system/js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="../media/system/js/jQuery.vietvang.validate.js"></script>
	<script type="text/javascript">
		$(document).ready(function(){
			$('#frm').validate({
			});
		});
</script>
<form action="index.php?option=com_town" id="frm" method="post" name="adminForm" id="adminForm" class="adminform form-validate">
	
    <div class="div-information" >
      <table border=0 class="table-information" style="width: 100%;">
         <!-- <tr style="visibility:hidden">
            <td style="min-width: 160px;"></td>
            <td style="min-width: 160px;"></td>
            <td style="min-width: 160px;"></td>
            <td style="min-width: 160px;"></td>
            <td style="min-width: 160px;"></td>
            <td style="min-width: 160px;"></td>
            <td style="min-width: 160px;"></td>
            <td style="min-width: 160px;"></td>
                 </tr>    -->
        <tr style="visibility:hidden">
            <td style="min-width: 160px;"></td>
            <td style="min-width: 150px;"></td>
            <td style="min-width: 134px;"></td>
            <td style="min-width: 143px;"></td>
            <td style="min-width: 137px;"></td>
            <td style="min-width: 150px;"></td>
            <td style="min-width: 160px;"></td>
            <td style="min-width: 220px;"></td>
        </tr>
        <tr>
            <td></td>
            <td colspan="3" class="err">※印は入力必須項目です。</td>
        </tr>
        <tr style="vertical-align: top;">    
            <td style="text-align: right;font-size: 1.091em;padding-right:5px;vertical-align: top;line-height: 30px">ID<span class="err" >※</span></td>            
            <td>
                <input readonly style="float: left;" data_required="true" vvName="number" class="inputbox_small" name="jform[TOWN_CODE]" value="<?php echo $this->row->TOWN_CODE; ?>" />
                <span name="msg_error"></span>
            </td>
            <td colspan="6"></td>
            
        </tr>
        <tr style="vertical-align: top;">
            <td style="text-align: right;font-size: 1.091em;padding-right:5px;vertical-align: top;line-height: 30px">市町村名<span class="err">※</span></td>
            <td colspan="2">
                <input style="float: left;" type="text" name="jform[TOWN_NAME]" class="inputbox big "  data_required="true" vvName="fullname" value="<?php echo $this->row->TOWN_NAME; ?>"/>
                <span name="msg_error"></span>
            </td>
            <td style="text-align: right;font-size: 1.091em;padding-right:5px;vertical-align: top;line-height: 30px">市町村（かな）<span class="err">※</span></td>
            <td colspan="2">
                <input style="float: left;" type="text" name="jform[TOWN_KANA]" class="inputbox big "  data_required="true" vvName="fullname" value="<?php echo $this->row->TOWN_KANA; ?>"/>
                <span name="msg_error"></span>
            </td>
        </tr>
        <tr style="vertical-align: top;">
            <td style="text-align: right;font-size: 1.091em;padding-right:5px;line-height:30px">市町村長名</td>
            <td colspan="2">
                <input type="text" name="jform[TOWN_HNAME]" class="inputbox big" value="<?php echo $this->row->TOWN_HNAME; ?>"/>
            </td>
            <td style="text-align: right;font-size: 1.091em;padding-right:5px;line-height:30px"> 市町村長就任日</td>
            <td colspan="2">
                <?php if($this->row->TOWN_HDATE != 0){ $dt = date('Y-m-d',strtotime($this->row->TOWN_HDATE));}else{ $dt=null;} echo JHtml::calendar($dt, 'jform[TOWN_HDATE]', 'jformTOWN_HDATE');?>
               <span name="msg_error"></span>
            </td>
        </tr>
        <tr style="vertical-align: top;line-height:30px">
            <td style="text-align: right;font-size: 1.091em;padding-right:5px;">教育長名</td>
            <td colspan="2">
                <input type="text" name="jform[TOWN_ENAME]" class="inputbox big" value="<?php echo $this->row->TOWN_ENAME; ?>"/>
            </td>
            <td style="text-align: right;font-size: 1.091em;padding-right:5px;"> 教育長就任日（新規）</td>
            <td colspan="2">
                <?php if($this->row->TOWN_EDATE != 0){ $dt = date('Y-m-d',strtotime($this->row->TOWN_EDATE));}else{ $dt=null;} echo JHtml::calendar($dt, 'jform[TOWN_EDATE]', 'jformTOWN_EDATE');?>
               <span name="msg_error"></span>
            </td>
        </tr>
        <tr style="vertical-align: top;line-height:30px">
            <td style="text-align: right;font-size: 1.091em;padding-right:5px;">議会議長名</td>
            <td colspan="2">
                <input type="text" name="jform[TOWN_DNAME]" class="inputbox big" value="<?php echo $this->row->TOWN_DNAME; ?>"/>
            </td>
            <td style="text-align: right;font-size: 1.091em;padding-right:5px;">合併状況 </td>
            <td colspan="3">
                <input type="text" name="jform[TOWN_UNIF]" class="inputbox big" value="<?php echo $this->row->TOWN_UNIF; ?>" />
            </td>
        </tr>
        <tr >
            <td style="text-align: right;font-size: 1.091em;padding-right:5px;vertical-align:middle">町の紹介</td>
            <td colspan="7"><textarea rows="5" name="jform[TOWN_PR]" style="width: 850px" ><?php echo $this->row->TOWN_PR; ?></textarea></td>
        </tr>
        <tr>
            <td style="text-align: right;font-size: 1.091em;padding-right:5px;vertical-align:middle">宣言</td>
            <td colspan="7"><textarea rows="5" name="jform[TOWN_DECL]" style="width: 850px" ><?php echo $this->row->TOWN_DECL; ?></textarea></td>
        </tr>
        <tr>
            <td colspan="8">
            <table border=0 width="100%">   
                <tr style="visibility:hidden">
                    <!-- <td style="min-width: 155px;"></td>
                    <td style="min-width: 200px;"></td>
                    <td style="min-width: 53px;"></td>
                    <td style="min-width: 200px;"></td>
                    <td style="min-width: 53px;"></td>
                    <td style="min-width: 200px;"></td>
                    <td style="min-width: 53px;"></td>
                    <td style="min-width: 200px;"></td>
                    <td style="min-width: 145px;"></td> -->
                    
                    <td style="min-width: 160px;"></td>
                    <td style="min-width: 200px;"></td>
                    <td style="min-width: 73px;"></td>
                    <td style="min-width: 200px;"></td>
                    <td style="min-width: 73px;"></td>
                    <td style="min-width: 200px;"></td>
                    <td style="min-width: 73px;"></td>
                    <td style="min-width: 200px;"></td>
                    <td style="min-width: 100px;"></td>
                </tr>              
                <tr style="vertical-align: top;">
                    <td style="text-align: right;font-size: 1.091em;padding-right:5px;vertical-align: top;line-height: 30px;">人口</td>
                    <td>
                        <input type="text" name="jform[TOWN_POPU]" class="inputbox_small" value="<?php echo $this->row->TOWN_POPU; ?>" vvName="digits_f"/>
                        <span name="msg_error" ></span>
                    </td>
                    <td style="text-align: right;font-size: 1.091em;padding-right:5px;vertical-align: top;line-height: 30px;">世帯数</td>
                    <td>
                        <input type="text" name="jform[TOWN_HOUS]" class="inputbox_small" value="<?php echo $this->row->TOWN_HOUS; ?>" vvName="digits_f"/>
                        <span name="msg_error" ></span>
                    </td>
                    <td style="text-align: right;font-size: 1.091em;padding-right:5px;vertical-align: top;line-height: 30px">面積</td>
                    <td>
                        <input type="text" name="jform[TOWN_AREA]" class="inputbox_small" value="<?php echo $this->row->TOWN_AREA; ?>" vvName="digits_f" />
                        <span name="msg_error" ></span>
                    </td>
                    <td style="text-align: right;font-size: 1.091em;padding-right:5px;vertical-align: top;line-height: 30px">人口密度</td>
                    <td>
                        <input type="text" name="jform[TOWN_DENS]" class="inputbox_small" value="<?php echo $this->row->TOWN_DENS; ?>" vvName="digits_f" />
                        <span name="msg_error" ></span>
                    </td>
                    
                </tr>
                <tr style="vertical-align: top;">
                    <td style="text-align: right;font-size: 1.091em;padding-right:5px;vertical-align: top;line-height: 30px;">保育園数</td>
                    <td><input type="text" name="jform[TOWN_NURS]" class="inputbox_small" vvName="digits_f" value="<?php echo $this->row->TOWN_NURS; ?>"/>
                        <span name="msg_error" ></span>
                    </td>
                    <td style="text-align: right;font-size: 1.091em;padding-right:5px;vertical-align: top;vertical-align: top;line-height: 30px;">幼稚園数</td>
                    <td><input type="text" name="jform[TOWN_CHIL]" class="inputbox_small" vvName="digits_f" value="<?php echo $this->row->TOWN_CHIL; ?>"/>
                        <span name="msg_error" ></span>
                    </td>
                    <td style="text-align: right;font-size: 1.091em;padding-right:5px;vertical-align: top;line-height: 30px;">小学校数</td>
                    <td><input type="text" name="jform[TOWN_ELEM]" class="inputbox_small" vvName="digits_f" value="<?php echo $this->row->TOWN_ELEM; ?>"/>
                        <span name="msg_error"></span>
                    </td>
                    <td style="text-align: right;font-size: 1.091em;padding-right:5px;vertical-align: top;line-height: 30px;">中学校数</td>
                    <td><input type="text" name="jform[TOWN_JUNI]" class="inputbox_small" vvName="digits_f" value="<?php echo $this->row->TOWN_JUNI; ?>"/>
                        <span name="msg_error"></span>
                    </td>
                </tr>
            </table>            
            </td>
        </tr>
        <tr style="vertical-align: top;">
            <td style="text-align: right;font-size: 1.091em;padding-right:5px;vertical-align: top;line-height: 30px;">高校数</td>
            <td colspan="2"><input type="text" name="jform[TOWN_HIGH]" class="inputbox_small" vvName="number" value="<?php echo $this->row->TOWN_HIGH; ?>"/>
                <span name="msg_error" ></span>
            </td>
            
        </tr>
        <tr>
            <td style="text-align: right;font-size: 1.091em;padding-right:5px;vertical-align:middle">主要産業</td>
            <td colspan="7"><textarea rows="5" name="jform[TOWN_INDU]" style="width: 850px" ><?php echo $this->row->TOWN_INDU; ?></textarea></td>
        </tr>
        <tr>
            <td style="text-align: right;font-size: 1.091em;padding-right:5px;line-height:30px">都市のシンボル（鳥）</td>
            <td><input type="text" name="jform[TOWN_SYM1]" style="width:100px" value="<?php echo $this->row->TOWN_SYM1; ?>" /></td>
            <td style="text-align: right;font-size: 1.091em;padding-right:5px;line-height:30px">都市のシンボル（花）</td>
            <td><input type="text" name="jform[TOWN_SYM2]" style="width:100px" value="<?php echo $this->row->TOWN_SYM2; ?>" /></td>
            <td style="text-align: right;font-size: 1.091em;padding-right:5px;line-height:30px">都市のシンボル（木）</td>
            <td><input type="text" name="jform[TOWN_SYM3]" style="width:100px" value="<?php echo $this->row->TOWN_SYM3; ?>" /></td>
            <td style="text-align: right;font-size: 1.091em;padding-right:5px;line-height:30px">都市のシンボル（その他）</td>
            <td><input type="text" name="jform[TOWN_SYM4]" style="width:100px" value="<?php echo $this->row->TOWN_SYM4; ?>" /></td>
        </tr>
        <tr>
            <td style="text-align: right;font-size: 1.091em;padding-right:5px;vertical-align:middle">交流都市（国内）</td>
            <td colspan="7"><textarea style="width:850px" rows="5" name="jform[TOWN_SIS1]" ><?php echo $this->row->TOWN_SIS1; ?></textarea></td>
        </tr>
        <tr>
            <td style="text-align: right;font-size: 1.091em;padding-right:5px;vertical-align:middle">交流都市（国外）</td>
            <td colspan="7"><textarea style="width:850px" rows="5" name="jform[TOWN_SIS2]" ><?php echo $this->row->TOWN_SIS2; ?></textarea></td>
        </tr>
     
      </table>
     </div>

    <fieldset class="" id="adminformfieldset">
         <legend>所在地（役場）</legend> 
         <table border=0 style="width:727px;">
            <tr style="vertical-align: top;">
               <td style="text-align: right;font-size: 1.091em;padding-right:5px;vertical-align: top;line-height: 30px;width:145px">役場　〒</td>
               <td style="float:left;width:270px">
                <input type="text" id="TOWN_POST" name="jform[TOWN_POST]" class="inputbox_town" value="<?php echo $this->row->TOWN_POST; ?>" vvname="postcode"/><input  id="search" type="button" value="住所検索"/>
                <span name="msg_error"></span>
                <span id="error_town" style="color: red; float: left; width: 100%;"></span>
               </td>
               <td style="text-align: right;font-size: 1.091em;padding-right:5px;width:100px"></td>
               <td style="min-width:200px"></td>
            </tr>
            <tr>
                <td style="text-align: right;font-size: 1.091em;padding-right:5px;width:213px;line-height:30px">都道府県</td>
                <td >
                    <select id="jformTOWN_PREF_CODE" name="jform[TOWN_PREF_CODE]" class="inputbox_town" style="clear: none;">
                                    <option value='0'>選択してください</option>
                       <?php 
                            foreach($this->getModel()->getPREF() as $pref){
                                $selected = $this->row->TOWN_PREF_CODE == $pref->PREF_CODE ? 'selected' : '';
                                echo "<option $selected value='$pref->PREF_CODE'>$pref->PREF_NAME</option>";
                            }
                       ?> 
                    </select>
                </td>
                <td style="width: 90px;" style="text-align: right;font-size: 1.091em;padding-right:5px;"></td>
                <td style="width:230px" ></td>
            </tr>
            <tr>
                <td style="text-align: right;font-size: 1.091em;padding-right:5px;line-height:30px">住所１</td>
                <td><input type="text" name="jform[TOWN_ADD1]" id="jformTOWN_ADD1" class="inputbox_town" value="<?php echo $this->row->TOWN_ADD1; ?>" /></td>
                <td style="text-align: right;font-size: 1.091em;padding-right:5px;line-height:30px">住所2</td>
                <td><input type="text" name="jform[TOWN_ADD2]" class="inputbox_town" value="<?php echo $this->row->TOWN_ADD2; ?>" /></td>
            </tr>
            <tr style="vertical-align: top;">
                <td style="text-align: right;font-size: 1.091em;padding-right:5px;line-height:30px">問い合わせ先</td>
                <td>
                    <input type="text" name="jform[TOWN_CONT]" class="inputbox_town" value="<?php echo $this->row->TOWN_CONT; ?>"/>
                    
                </td>
                <td style="text-align: right;font-size: 1.091em;padding-right:5px;vertical-align: top;line-height: 30px;">URL</td>
                <td>
                    <input type="text" name="jform[TOWN_URL]" class="inputbox_town" value="<?php echo $this->row->TOWN_URL; ?>" vvName="website"/>
                    <span name="msg_error"></span>
                </td>
            </tr>
            <tr style="vertical-align: top;">
                <td style="text-align: right;font-size: 1.091em;padding-right:5px;line-height: 30px;vertical-align: top;">TEL</td>
                <td>
                    <input type="text" name="jform[TOWN_TEL]" class="inputbox_town" value="<?php echo $this->row->TOWN_TEL; ?>" vvName="phone"/>
                    <span name="msg_error"></span>
                </td>
                <td style="text-align: right;font-size: 1.091em;padding-right:5px;vertical-align: top;line-height: 30px;"> FAX</td>
                <td>
                    <input type="text" name="jform[TOWN_FAX]" class="inputbox_town" value="<?php echo $this->row->TOWN_FAX; ?>" vvName="fax"/>
                    <span name="msg_error"></span>
                </td>
            </tr>
             <tr style="vertical-align: top;">
                <td style="text-align: right;font-size: 1.091em;padding-right:5px;vertical-align: top;line-height: 30px;;">E-Mail</td>
                <td>
                    <input type="text" name="jform[TOWN_MAIL]" class="inputbox_town" value="<?php echo $this->row->TOWN_MAIL; ?>" vvName="email"/>
                    <span name="msg_error"></span>
                </td>
                <td style="text-align: right;font-size: 1.091em;padding-right:5px;line-height:30px">最寄駅</td>
                <td><input type="text" name="jform[TOWN_STAT]" class="inputbox_town" value="<?php echo $this->row->TOWN_STAT; ?>" /></td>
            </tr>
            <tr>
                <td style="text-align: right;font-size: 1.091em;padding-right:5px;line-height:30px">地図</td></td>
                <td>
                    <input type="text" name="jform[TOWN_MURL]" class="inputbox_town"value="<?php echo $this->row->TOWN_MURL; ?>" />
                    <span name="msg_error"></span>
                </td>
                <td style="text-align: right;font-size: 1.091em;padding-right:5px;"></td>
                <td></td>
            </tr>
         </table>
    </fieldset>
      <div class="div-information" >    
     <table border=0 class="table-information" style="width: 100%;">
       
        <tr>
            <td style="text-align: right;font-size: 1.091em;padding-right:5px;width:152px;vertical-align:middle">備考</td>
            <td><textarea rows="5" name="jform[TOWN_NOTE]" style="width: 850px" ><?php echo $this->row->TOWN_NOTE; ?></textarea></td>
        </tr>
        <!--<tr>
            <td style="text-align: right;font-size: 1.091em;padding-right:5px;" >その他情報</td>
            <td><textarea rows="5" name="jform[TOWN_MURL]" style="width: 850px" ><?php echo $this->row->TOWN_MURL; ?></textarea></td>
        </tr>-->
       </table>
       </div>
       	<div>
        <input name="task" type="hidden"/>
	</div>
</form>
<script> 
    Joomla.submitbutton = function(task){
        if(task == 'cancel'){
            window.location.href = "index.php?option=com_town";
        }
        if(document.formvalidator.isValid(document.id('frm'))){
            Joomla.submitform(task, document.getElementById('frm'));
        } 
       
    }
    jq('#search').click(function(){
        jq.ajax({
          url: 'index.php?option=com_town&task=searchTOWN_POST&tmpl=component'
            +'&TOWN_POST='+jq('#TOWN_POST').val(),
          context: document.body,
          dataType: "JSON"
        }).done(function(data ) {
            if(data.message == 'ok'){
                jq('#jformTOWN_ADD1').val(data.city + data.address);
                jq("#jformTOWN_PREF_CODE option").filter(function() {
                    //may want to use $.trim in here
                    return jq(this).text() == data.pref; 
                }).prop('selected', true);
                jq('#error_town').hide();
            } else {
                jq('#error_town').show();
                jq('#error_town').html(data.message);
            }
        });
    });
    
    window.addEvent('domready', function() {Calendar.setup({
        	// Id of the input field
        	inputField: "jformTOWN_HDATE",
        	// Format of the input field
        	ifFormat: "%Y/%m/%d",
        	// Trigger for the calendar (button ID)
        	button: "jformTOWN_HDATE",
        	// Alignment (defaults to "Bl")
        	align: "Bl",
        	singleClick: true,
        	firstDay: 0
    	});
    });
    window.addEvent('domready', function() {Calendar.setup({
        	// Id of the input field
        	inputField: "jformTOWN_EDATE",
        	// Format of the input field
        	ifFormat: "%Y/%m/%d",
        	// Trigger for the calendar (button ID)
        	button: "jformTOWN_EDATE",
        	// Alignment (defaults to "Bl")
        	align: "Bl",
        	singleClick: true,
        	firstDay: 0
    	});
     });

</script>